﻿package com.firewolf.iteratorAndComponent.combine;

import java.util.ArrayList;
import java.util.Iterator;
/**
 * 菜单和菜单项一样，都是MenuComponent
 * @author Administrator
 *
 */
public class MyMenu extends MenuComponent{
	private ArrayList<MenuComponent> menuComponents = new ArrayList<MenuComponent>();
	private String name ;
	private String description ;
	public MyMenu(String name , String description) {
		this.name = name ;
		this.description = description ;
	}
	@Override
	public void add(MenuComponent menuComponent) {
		menuComponents.add(menuComponent);
	}
	@Override
	public void remove(MenuComponent menuComponent) {
		menuComponents.remove(menuComponent);
	}
	@Override
	public MenuComponent getChild(int i) {
		return menuComponents.get(i);
	}
	@Override
	public String getName() {
		return name ;
	}
	@Override
	public String getDescription() {
		return description ;
	}
	@Override
	public void print() {
		System.out.println("-------------------------");
		System.out.println("Menu: "+getName()+" , "+getDescription()+" :");
		Iterator<MenuComponent> iterator = menuComponents.iterator();
		while(iterator.hasNext()){
			MenuComponent menuComponent = iterator.next();
			menuComponent.print();
		}
	}
	@SuppressWarnings("rawtypes")
	@Override
	public Iterator getIterator() {
		return new CompositeIterator(menuComponents.iterator());
	}
	
}
